package com.gjy.sql.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.fill.FillWrapper;

import java.util.List;
import java.util.Map;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-07-16 08:46:34
 */
public class ExcelTemplate {

    private static final String BASE_PATH = "D:\\code\\java\\microservice_spc\\sql\\src\\main\\resources\\excel\\template\\";
    public static final String MORE_SHEET = BASE_PATH + "moresheet.xlsx";

    public void exportTemplate(String writePath, Map<String, List<Map<String, String>>> data) {
        try (ExcelWriter writer = EasyExcel.write(writePath).withTemplate(MORE_SHEET).build()) {
            WriteSheet s1 = EasyExcel.writerSheet("组织数据").build();
            FillWrapper fw1 = new FillWrapper("d1", data.get("d1"));
            writer.fill(fw1, s1);

            WriteSheet s2 = EasyExcel.writerSheet("金额数据").build();
            FillWrapper fw2 = new FillWrapper("d2", data.get("d2"));
            writer.fill(fw2, s2);

            WriteSheet s3 = EasyExcel.writerSheet("合同数据").build();
            FillWrapper fw3 = new FillWrapper("d3", data.get("d3"));
            writer.fill(fw3, s3);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
